package timer;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Timer;

/**
 * @ClassName MyTimer
 * @Description TODO
 * @Author Wxg
 * @Date 2018/11/13 15:00
 * @Version 1.0
 */
public class MyTimerV4 {
    public static void main(String[] args) throws InterruptedException {
        Timer timer = new Timer();
        MyTimerTask myTimerTask = new MyTimerTask("No.1");

        Calendar calendar = Calendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println("当前时间 : " + sdf.format(calendar.getTime()));

        myTimerTask.setName("schedule2");
        timer.schedule(myTimerTask, 1000L);

        Thread.sleep(4000L);
        System.out.println("\n退出main线程……\n");
        System.exit(0);
    }
}
